package com.api.weavernorth.hlylogind;



import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import weaver.conn.RecordSet;
import weaver.general.Util;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.io.IOException;


/**
 * 统一认证获取loginid和邮箱对应关系
 */

@Path("/hly")
public class HlyToLogin extends HttpServlet {
    private static Log log = org.apache.commons.logging.LogFactory.getLog(HlyToLogin.class.getName());

    @POST
    @Path("/hlytologin")
    @Produces(MediaType.APPLICATION_JSON)
    public JSONObject editHrmmess(@Context HttpServletRequest httpservletrequest, @Context HttpServletResponse httpservletresponse, String loginid)
            throws ServletException, IOException {
        log.info("查询emil:"+loginid.toString());
        RecordSet rs = new RecordSet();
        JSONObject jsonReturn = new JSONObject();
        JSONObject jsonObject = JSONObject.fromObject(loginid);
        String strLoginid = Util.null2String(jsonObject.get("loginid"));
        //查询邮箱返回
        String strSql = "select oayxdz from uf_hlylogin  where hlyloginid=? ";
        rs.executeQuery(strSql, strLoginid);
        if (rs.next()) {
            jsonReturn.put("emil", Util.null2String(rs.getString("oayxdz")));
            jsonReturn.put("stauts", "0");
            jsonReturn.put("mess", "请求成功");
            log.info("返回信息成功:"+jsonReturn.toString());
            return jsonReturn;
        } else {
            jsonReturn.put("stauts", "1");
            jsonReturn.put("mess", "请求失败");
            log.info("返回信息失败:"+jsonReturn.toString());
            return jsonReturn;
        }
    }


}